var Dashboard = function () {

    return {
        initAmChart1: function (chartData) {
            if (typeof (AmCharts) === 'undefined' || $('#dashboard_amchart_1').size() === 0) {
                return;
            }

            /*var chartData = [{
                "date": "2018-04",
                "amount": 0,
                "orderCount": 0,
                "skuCount": 501
            }, {
                "date": "2018-05",
                "amount": 1222.22,
                "orderCount": 30,
                "skuCount": 443
            }, {
                "date": "2018-06",
                "amount": 5881,
                "orderCount": 74,
                "skuCount": 405
            }, {
                "date": "2018-07-08",
                "amount": 238,
                "orderCount": 29.76,
                "skuCount": 309
            }, {
                "date": "2018-08-09",
                "amount": 218,
                "orderCount": 32.8,
                "skuCount": 287
            }, {
                "date": "2018-09-10",
                "amount": 349,
                "orderCount": 35.49,
                "skuCount": 485
            }, {
                "date": "2018-10-11",
                "amount": 603,
                "orderCount": 39.1,
                "skuCount": 890
            }, {
                "date": "2018-11-12",
                "amount": 534,
                "orderCount": 39.74,
                "skuCount": 810
            }, {
                "date": "2018-12-13",
                "amount": 425,
                "skuCount": 670,
                "orderCount": 40.75,
            }, {
                "date": "2019-01-14",
                "amount": 225,
                "orderCount": 36.1,
                "skuCount": 470,
                "bulletClass": "lastBullet"
            }, {
                "date": "2019-02"
            }];*/
            var chart = AmCharts.makeChart("dashboard_amchart_1", {
                type: "serial",
                fontSize: 12,
                fontFamily: "Open Sans",
                dataDateFormat: "YYYY-MM",
                dataProvider: chartData,
                language: "tr",
                addClassNames: true,
                startDuration: 1,
                color: "#6c7b88",
                marginLeft: 0,

                categoryField: "date",
                categoryAxis: {
                    parseDates: true,
                    minPeriod: "MM",
                    autoGridCount: false,
                    gridCount: 50,
                    gridAlpha: 0.1,
                    gridColor: "#FFFFFF",
                    axisColor: "#555555",
                    dateFormats: [{
                        period: 'DD',
                        format: 'DD'
                    }, {
                        period: 'WW',
                        format: 'MMM DD'
                    }, {
                        period: 'MM',
                        format: 'MMM'
                    }, {
                        period: 'YYYY',
                        format: 'YYYY'
                    }]
                },

                valueAxes: [{
                    id: "a1",
                    title: "销售额",
                    gridAlpha: 0,
                    axisAlpha: 0
                }, {
                    id: "a2",
                    position: "right",
                    title: "订单量",
                    gridAlpha: 0,
                    axisAlpha: 0,
                    labelsEnabled: true
                }, {
                    id: "a3",
                    position: "right",
                    gridAlpha: 0,
                    axisAlpha: 0,
                    inside: true,
                    labelsEnabled: false
                }],
                graphs: [{
                    id: "g1",
                    valueField: "amount",
                    title: "销售额",
                    type: "column",
                    fillAlphas: 0.7,
                    valueAxis: "a1",
                    balloonText: "[[value]] 元",
                    legendValueText: "[[value]] 元",
                    legendPeriodValueText: "总: [[value.sum]] 元",
                    lineColor: "#08a3cc",
                    alphaField: "alpha",
                }, {
                    id: "g2",
                    valueField: "orderCount",
                    classNameField: "bulletClass",
                    title: "订单量",
                    type: "line",
                    valueAxis: "a2",
                    lineColor: "#786c56",
                    lineThickness: 1,
                    legendValueText: "[[value]]单",
                    legendPeriodValueText: "总: [[value.sum]] 单",
                    descriptionField: "value",
                    bullet: "round",
                    //bulletSizeField: "orderCount",
                    bulletBorderColor: "#02617a",
                    bulletBorderAlpha: 1,
                    bulletBorderThickness: 2,
                    bulletColor: "#89c4f4",
                    //labelText: "[[value]]单",
                    labelPosition: "right",
                    balloonText: "[[value]]单",
                    showBalloon: true,
                    animationPlayed: true,
                }, {
                    id: "g3",
                    title: "SKU",
                    valueField: "skuCount",
                    type: "line",
                    valueAxis: "a3",
                    lineAlpha: 0.8,
                    lineColor: "#e26a6a",
                    balloonText: "[[value]]件",
                    lineThickness: 1,
                    legendValueText: "[[value]]件",
                    legendPeriodValueText: "总: [[value.sum]] 件",
                    bullet: "square",
                    bulletBorderColor: "#e26a6a",
                    bulletBorderThickness: 1,
                    bulletBorderAlpha: 0.8,
                    dashLengthField: "dashLength",
                    animationPlayed: true
                }],

                chartCursor: {
                    zoomable: false,
                    categoryBalloonDateFormat: "MM",
                    cursorAlpha: 0,
                    categoryBalloonColor: "#e26a6a",
                    categoryBalloonAlpha: 0.8,
                    valueBalloonsEnabled: false
                },
                legend: {
                    bulletType: "round",
                    equalWidths: false,
                    valueWidth: 120,
                    useGraphSettings: true,
                    color: "#6c7b88"
                }
            });
        },
        init: function (chartData) {
            this.initAmChart1(chartData);
        },
        initStockChart: function (charId, chartData) {
            if (typeof (AmCharts) === 'undefined' || $('#' + charId).size() === 0) {
                return;
            }
            AmCharts.makeChart(charId, {
                type: "serial",
                fontSize: 12,
                fontFamily: "Open Sans",
                dataProvider: chartData,
                language: "tr",
                addClassNames: true,
                startDuration: 1,
                color: "#6c7b88",
                marginLeft: 0,
                categoryField: "name",
                categoryAxis: {
                    autoGridCount: false,
                    gridCount: 50,
                    gridAlpha: 0.1,
                    gridColor: "#FFFFFF",
                    axisColor: "#555555"
                },
                valueAxes: [{
                    id: "a1",
                    title: "数量",
                    gridAlpha: 0,
                    axisAlpha: 0
                }],
                graphs: [{
                    id: "g1",
                    valueField: "usableAmount",
                    title: "当前库存",
                    type: "column",
                    fillAlphas: 0.7,
                    valueAxis: "a1",
                    balloonText: "[[value]] 件",
                    legendValueText: "[[value]] 件",
                    legendPeriodValueText: "共: [[value.sum]] 件",
                    lineColor: "#08a3cc",
                    alphaField: "alpha"
                }],
                chartCursor: {
                    zoomable: false,
                    cursorAlpha: 0,
                    categoryBalloonColor: "#e26a6a",
                    categoryBalloonAlpha: 0.8,
                    valueBalloonsEnabled: false
                },
                legend: {
                    bulletType: "round",
                    equalWidths: false,
                    valueWidth: 120,
                    useGraphSettings: true,
                    color: "#6c7b88"
                }
            });
        }
    };

}();